package com.abel;

import org.apache.zookeeper.KeeperException;
import org.junit.Test;

import java.io.IOException;
import java.util.List;

/**
 * @author xiachao
 * @date 2019/4/1
 */
public class ZookeeperDemo {
    private static String hosts = "127.0.0.1";
    private static String groupName = "zoo";
    private ConnectionWatcher createGroup = null;

    @Test
    public void testCreate(){
        CreateWatcher createWatcher = new CreateWatcher();

        try {
            createWatcher.connect(hosts);
            createWatcher.create("heaven/cow");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testList() throws IOException, InterruptedException {
        ListGroupWatcher listGroupWatcher = new ListGroupWatcher();
        listGroupWatcher.connect(hosts);
        List<String> children = listGroupWatcher.list("/heaven");
        for(String c : children){
            System.out.print(c+"\t");
        }
    }

}
